package com.liudadan.aspect_04;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {

    @Around("execution(* com..aop_04.impl.*.*(..))")
    public Object manageTransaction(ProceedingJoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        Object targetMethodReturnValue = null;
        long startTime = System.currentTimeMillis();
        try {
            System.out.println("方法进来了！！");
            targetMethodReturnValue = joinPoint.proceed(args);
            System.out.println("方法结束了");
        } catch (Throwable throwable) {
            System.out.println("方法报错了");
        } finally {
            long endTime = System.currentTimeMillis();
            System.out.println("方法执行了" + (endTime - startTime) + "毫秒");
        }
        return targetMethodReturnValue;
    }
}
